package com.brds.netty.io;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author barudisshu
 */
public class BlockingIO {

    public static void main(String[] args) throws Exception {

        ServerSocket serverSocket = new ServerSocket(1978);
        Socket clientSocket = serverSocket.accept(); // 阻塞直到连接建立

        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

        String request, response;
        while ((request = in.readLine()) != null) {
            if ("Done".equals(request))
                break;
            response = processRequest(request);
            out.print(response);

            System.out.println(response);
        }
    }

    private static String processRequest(String request) {

        return request;
    }

}
